﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DemoConstructor.Demo5
{
    /// <summary>
    /// Static Constructor
    /// </summary>
    class Demo5
    {
        public static void RunDemo5()
        {
            SecondClass theSecond = new SecondClass();
            Console.WriteLine(Environment.NewLine);
            ThirdClass theThird = new ThirdClass();
        }
    }

    class FirstClass
    {
        static string fStatic = FirstClass.Run("FirstClass Static Variable");
        public string fPublic = FirstClass.Run("FirstClass Public Variable");
 
        public FirstClass()
        {
            Console.WriteLine("Constructor with no param of FirstClass was called. (public)");
            fStatic = FirstClass.Run("FirstClass Static Variable in public Constructor");
            fPublic = FirstClass.Run("FirstClass Public Variable in public Constructor");
        }

        static FirstClass()
        {
            Console.WriteLine("Constructor with no param of FirstClass was called. (static)");            
            fStatic = FirstClass.Run("FirstClass Static Variable in static Constructor");
            //An object reference is required for the non-static field, method, or property 'DemoConstructor.Demo5.FirstClass.fPublic'	           
            //fPublic = string.Empty;
        }

        protected static string Run(string message)
        {
            Console.WriteLine(message);
            return string.Empty;
        }
    }

    class SecondClass : FirstClass
    {
        static string sStatic = FirstClass.Run("SecondClass Static Variable");
        private string sPublic = FirstClass.Run("SecondClass Public Variable");
       
        public SecondClass()
        {
            Console.WriteLine("Constructor with no param of SecondClass was called. (public)");
            sStatic = FirstClass.Run("SecondClass Static Variable in public Constructor");
            this.sPublic = FirstClass.Run("SecondClass S Public Variable in public Constructor");
                        
            this.fPublic = FirstClass.Run("SecondClass F Public Variable in public Constructor");
        }

        static SecondClass()
        {
            Console.WriteLine("Constructor with no param of SecondClass was called. (static)");
            sStatic = FirstClass.Run("SecondClass Static Variable in static Constructor");
                        
            //this.sPublic = FirstClass.Run("SecondClass S Public Variable in public Constructor");
            //this.fPublic = FirstClass.Run("SecondClass F Public Variable in public Constructor");
        }
    }

    class ThirdClass : FirstClass
    {
        public ThirdClass()
            :base()
        {
            Console.WriteLine("Constructor with no param of ThirdClass was called. (public)");
        }

        /// <summary>
        /// DemoConstructor.Demo5.ThirdClass.ThirdClass()': static constructor cannot have an explicit 'this' or 'base' constructor call
        /// </summary>
        //static ThirdClass()
        //    :base()        
        //{
        //}
    }
}
